﻿using System;
using System.Collections.Generic;
using System.Text;

namespace natureskitchen
{
    public class mysql
    {
        static string connectionstring = "Server=74.208.102.196;Port=3306;Database=natureskitchen;Uid=franklin;Pwd=frklin;";
        static MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection(connectionstring);
        public static bool isConnected;

        public static MySql.Data.MySqlClient.MySqlConnection connectDB()
        {
            bool success = true;

            if (isConnected == false)
            {
                try
                {
                    conn.Open();
                }
                catch (MySql.Data.MySqlClient.MySqlException mysqlEX)
                {
                    isConnected = false;
                    success = false;
                    Console.WriteLine("You have received an error while connecting to the database: " + mysqlEX.Message);
                }
                if (success)
                {
                    isConnected = true;
                }
            }
            return conn;
        }

        public static void disconnectDB()
        {
            if (isConnected)
            {
                conn.Close();
            }
        }

        public bool IsConnected()
        {
            return isConnected;
        }
    }
}
